<style>
  .picImg {
    width: 40px;
    height: 40px;
  }
</style>
<template>
  <div class="app-container">
    <!--设置参数-->
    <div class="filter-container">
      <el-button class="filter-item" type="primary" icon="el-icon-edit"
                 @click="handleAdd">设置参数
      </el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row>

      <el-table-column align="center" min-width="100" label="配置名称" prop="cfgName"/>
      <el-table-column align="center" min-width="100" label="配置值" prop="cfgValue"/>
      <!--<el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width">-->
        <!--<template slot-scope="scope">-->
            <!--<el-button type="primary" size="mini"-->
                     <!--@click="handleEdit(scope.row)">设置-->
          <!--</el-button>-->
        <!--</template>-->
      <!--</el-table-column>-->
    </el-table>
    <el-dialog :visible.sync="editDialogVisible" title="设置参数">
      <el-form ref="editForm" :rules="editFormRules" :model="editForm" status-icon label-position="left"
               label-width="100px" style="width: 400px; margin-left:50px;">
        <el-form-item label="配置名称" prop="cfgName">
          <el-input v-model="editForm.cfgName" placeholder="配置名称"/>
        </el-form-item>
        <el-form-item label="配置值" prop="cfgValue">
          <el-input v-model="editForm.cfgValue" auto-complete="off" placeholder="配置值"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="doCreate">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { doGet, doPost } from '@/api'
//  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  import checkPermission from '@/utils/permission' // 权限判断函数

  const FETCH_PAGE = 'config.html';
  const FETCH_URL = {
    LIST: `${FETCH_PAGE}?op=search`,
    CREATE: `${FETCH_PAGE}?op=set`,

  }

  export default {
    name: 'bank',
//    components: { Pagination },
    filters: {
        // accTyped: function(val){
        //     return function (val){
        //         return {0: "服务费账户",1: "代付账户"}[val] || "未知"
        //     }
        // },
    },
    data() {
      return {
        list: [],
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
        },
        editForm: {
          cfgName:undefined,
          cfgValue:undefined,
        },
        editFormRules: {
          cfgName: [{ required: true, message: '配置名称不可为空', trigger: 'blur' }],
        },
        editDialogVisible: false,
//        editIndex:undefined
      }
    },
    created() {
      this.getList()
    },
    methods: {
      checkPermission,
      getList() {
        this.listLoading = true
        doGet(FETCH_URL.LIST, {}).then(response => {
          console.log(response)
          this.list = response.rows
          this.listLoading = false
        }).catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
      },
      handleAdd() {
        this.editForm = {
          cfgName: undefined,
          cfgValue: undefined,
        }
        this.editDialogVisible = true
        this.$nextTick(() => {
          this.$refs['editForm'].clearValidate()
        })
      },
      doCreate() {
        this.$refs['editForm'].validate(valid => {
          if (valid) {
            let sendData = {
              ...this.editForm,
            }
            doGet(FETCH_URL.CREATE, sendData)
              .then(response => {
                this.getList()
                this.editDialogVisible = false
                this.$notify.success({
                  title: '成功',
                  message: '参数设置成功'
                })
              })
              .catch(response => {
                this.$notify.error({
                  title: '失败',
                  message: response.message
                })
              })
          }
        })
      },
//      handleEdit(row) {
//        this.editForm = Object.assign({}, row)
//        this.editIndex = this.list.indexOf(row)
//        this.editDialogVisible = true
//        this.$nextTick(() => {
//          this.$refs['editForm'].clearValidate()
//        })
//      },
//      doEdit() {
//        this.$refs['editForm'].validate(valid => {
//          if (valid) {
//            let sendData = {
//              ...this.editForm,
//            }
//            doGet(FETCH_URL.CREATE, sendData)
//              .then(response => {
//                this.getList()
//                this.editDialogVisible = false
//                this.list[this.editIndex] = this.editForm
//                this.$notify.success({
//                  title: '成功',
//                  message: '参数设置成功'
//                })
//              })
//              .catch(response => {
//                this.$notify.error({
//                  title: '失败',
//                  message: response.message
//                })
//              })
//          }
//        })
//      },
    }
  }
</script>
